package io.wins.vertx.service.impl;

import io.vertx.core.Vertx;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.wins.vertx.entity.Role;
import io.wins.vertx.service.BaseService;
import io.wins.vertx.service.RoleService;

public class RoleServiceImpl extends BaseService implements RoleService {
    public RoleServiceImpl(final Vertx vertx) {
        this.vertx = vertx;
    }

    @Override
    public RoleService getRoleById(final String id, final Message tMessage) {
        final JsonObject sqlMes = new JsonObject()
            .put(SQL, "select * from ds_role where id = ?")
            .put(PARAMS, new JsonArray().add(id));
        this.querySql(sqlMes, this.resultQuery(tMessage, false, null, "Error"));
        return this;
    }

    @Override
    public RoleService listRole(final Message tMessage) {
        final JsonObject sqlMes = new JsonObject()
            .put(SQL, "select * from ds_role");
        this.querySql(sqlMes, this.resultQuery(tMessage, false, null, "Error"));
        return this;
    }

    @Override
    public RoleService createRole(final Role role, final Message tMessage) {
        final JsonObject sqlMes = new JsonObject()
            .put(SQL, "insert into ds_role (id, role_name, description, created_on, updated_on) VALUES (? ? ? ? ?)")
            .put(PARAMS, new JsonArray()
                .add(role.getId())
                .add(role.getRoleName())
                .add(role.getDescription())
                .add(role.getCreatedOn())
                .add(role.getUpdatedOn()));
        this.insertSql(sqlMes, this.resultUpdate(tMessage, "Error"));
        return this;
    }

    @Override
    public RoleService deleteRole(final String id, final Message tMessage) {
        return this;
    }
}
